<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>后台管理|标签管理</title>

    <!-- Bootstrap -->
    <link href="/resource/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/resource/css/dropdowns-enhancement.css"/>
    <link rel="stylesheet" href="/resource/css/bootstrap-table.min.css"/>
    <link rel="stylesheet" href="/resource/css/admin.css"/>
    <link rel="stylesheet" href="/resource/css/toastr.min.css"/>
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>

<% include ../Admin/include/nav.html %> <!--顶部导航-->
<div class="container">
    <div class="row">
        <div class="col-sm-3 col-md-2">
            <% include ../Admin/include/sidebar.html %> <!--左侧菜单-->

        </div>
        <div class="col-sm-9 col-md-10 main">
            <h4 class="page-header"><span aria-hidden="true" class="glyphicon glyphicon-tags"></span> 标签管理</h4>
            <a href="/admin/category/edit" type="button" class="btn btn-primary mbot10">
                <span aria-hidden="true" class="glyphicon glyphicon-plus"></span>
                添加分类</a>

            <div style="margin-top: -55px">
                <table id="table"
                       data-toggle="table"
                       data-url="/admin/tag/data"
                       data-show-columns="true"
                       data-search="true"
                       data-show-refresh="true"
                       data-show-toggle="true"
                       data-pagination="true"
                       data-side-pagination="server"
                       data-page-list="[5, 10, 20, 50, 100, 200]"
                       data-page-size="20"
                        >
                    <thead>
                    <tr>
                        <th data-field="state" data-checkbox="true"></th>
                        <th data-field="tid" data-formatter="idFormatter">ID</th>
                        <th data-field="tagname">名称</th>
                        <th data-field="gid">文章ID</th>
                        <th data-field="operate" data-formatter="operateFormatter" data-events="operateEvents">编辑</th>
                    </tr>
                    </thead>
                </table>
            </div>


        </div>
    </div>
</div>
<% include ../Admin/include/footer.html %>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="/resource/js/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="/resource/js/bootstrap.min.js"></script>
<script src="/resource/js/dropdowns-enhancement.min.js"></script>
<script src="/resource/js/bootstrap-table.js"></script>
<script src="/resource/js/bootstrap-table-zh-CN.js"></script>
<script src="/resource/js/bootbox.min.js"></script>
<script src="/resource/js/toastr.min.js"></script>
<script>
    function operateFormatter(value, row, index) {
        return [
            '<a class="edit ml10" href="javascript:void(0)" title="编辑">',
            '<i class="glyphicon glyphicon-edit"></i>',
            '</a>',
            '&nbsp;&nbsp;<a class="remove ml10" href="javascript:void(0)" title="删除">',
            '<i class="glyphicon glyphicon-remove"></i>',
            '</a>'
        ].join('');
    }

    window.operateEvents = {
        'click .edit': function (e, value, row, index) {
            alert('You click edit icon, row: ' + JSON.stringify(row));
            console.log(value, row, index);
        },
        'click .remove': function (e, value, row, index) {
//            alert('You click remove icon, row: ' + JSON.stringify(row));
//            console.log(value, row, index);
            var tid = row.tid;
            bootbox.confirm({
                size: 'small',
                message: "你确定要删除所选文章吗？",
                callback: function (result) {
                    if (result) {
                        $.ajax({
                            url: '/admin/tag/dele',
                            data: {tid: tid},
                            type: "GET",
                            dataType: "json",
                            success: function (data) {
                                $("#table").bootstrapTable('refresh');

                                toastr.success('成功删除' + data + '条标签！');
                            }
                        });

                    }

                }
            });
        }
    };

</script>
</body>
</html>